package net.minecraft.src;

import java.io.File;

public class WorldPPH extends World
{

    public WorldPPH(World world, WorldProvider worldprovider)
    {
        super(world, worldprovider);
        chunkProvider = getChunkProvider();
		worldProvider.registerWorld(this);
    }
	
    protected IChunkProvider getChunkProvider()
    {
        File file = ((SaveHandler)saveHandler).getSaveDirectory();
        Object obj = null;
        if(saveHandler instanceof SaveOldDir)
        {
            File file1 = new File(file, "DIM5");
            file1.mkdirs();
            obj = new ThreadedChunkLoader(file1);
        } else
        if(saveHandler instanceof SaveHandler)
        {
            File file2 = new File(file, "DIM5");
            file2.mkdirs();
            obj = new ChunkLoader(file2, true);
        }
        return new ChunkProvider(this, ((IChunkLoader) (obj)), worldProvider.getChunkProvider());
    }
	
	public IChunkLoader getChunkLoader(WorldProvider worldprovider)
    {
        File file = ((SaveHandler)saveHandler).getSaveDirectory();
        if(saveHandler instanceof SaveOldDir && worldprovider instanceof WorldProviderPrePrehistoric)
        {
            File file1 = new File(file, "DIM5");
            file1.mkdirs();
            return new ThreadedChunkLoader(file1);
        } else
		if(saveHandler instanceof SaveHandler && worldprovider instanceof WorldProviderHell)
        {
            File file2 = new File(file, "DIM5");
            file2.mkdirs();
            return new ChunkLoader(file2, true);
        }
		return new ChunkLoader(file, true);
    }
	
	public Vec3D getSkyColor(Entity entity, float f)
    {
        float f1 = getCelestialAngle(f);
        float f2 = MathHelper.cos(f1 * 3.141593F * 2.0F) * 2.0F + 0.5F;
        if(f2 < 0.0F)
        {
            f2 = 0.0F;
        }
        if(f2 > 1.0F)
        {
            f2 = 1.0F;
        }
        int i = MathHelper.floor_double(entity.posX);
        int j = MathHelper.floor_double(entity.posZ);
        float f3 = getWorldChunkManager().func_35554_b(i, 64, j);
		int k = 0x000000;
		BiomeGenBase biomegenbase = getWorldChunkManager().getBiomeGenAt(i, j);
		if(biomegenbase instanceof BiomeGenPPHCoalSwamp || biomegenbase instanceof BiomeGenPPHCalamitesSwamp || biomegenbase instanceof BiomeGenPPHRainforest || biomegenbase instanceof BiomeGenPPHHighlands || biomegenbase instanceof BiomeGenPPHIsland)
		{
			k = getWorldChunkManager().getBiomeGenAt(i, j).getSkyColorByTemp(f3);
		} else
		{
			k = 0x336666;
		}
        float f4 = (float)(k >> 16 & 0xff) / 255F;
        float f5 = (float)(k >> 8 & 0xff) / 255F;
        float f6 = (float)(k & 0xff) / 255F;
        f4 *= f2;
        f5 *= f2;
        f6 *= f2;
        float f7 = getRainStrength(f);
        if(f7 > 0.0F)
        {
            float f8 = (f4 * 0.3F + f5 * 0.59F + f6 * 0.11F) * 0.6F;
            float f10 = 1.0F - f7 * 0.75F;
            f4 = f4 * f10 + f8 * (1.0F - f10);
            f5 = f5 * f10 + f8 * (1.0F - f10);
            f6 = f6 * f10 + f8 * (1.0F - f10);
        }
        float f9 = getWeightedThunderStrength(f);
        if(f9 > 0.0F)
        {
            float f11 = (f4 * 0.3F + f5 * 0.59F + f6 * 0.11F) * 0.2F;
            float f13 = 1.0F - f9 * 0.75F;
            f4 = f4 * f13 + f11 * (1.0F - f13);
            f5 = f5 * f13 + f11 * (1.0F - f13);
            f6 = f6 * f13 + f11 * (1.0F - f13);
        }
        if(lightningFlash > 0)
        {
            float f12 = (float)lightningFlash - f;
            if(f12 > 1.0F)
            {
                f12 = 1.0F;
            }
            f12 *= 0.45F;
            f4 = f4 * (1.0F - f12) + 0.8F * f12;
            f5 = f5 * (1.0F - f12) + 0.8F * f12;
            f6 = f6 * (1.0F - f12) + 1.0F * f12;
        }
        return Vec3D.createVector(f4, f5, f6);
    }
	
	public void tick()
    {
        if(getWorldInfo().isHardcoreModeEnabled() && difficultySetting < 3)
        {
            difficultySetting = 3;
        }
        getWorldChunkManager().func_35561_b();
        updateWeather();
        if(isAllPlayersFullyAsleep())
        {
            boolean flag = false;
            if(spawnHostileMobs)
            {
                if(difficultySetting < 1);
            }
            if(!flag)
            {
                long l = worldInfo.getWorldTime() + 24000L;
                worldInfo.setWorldTime(l - l % 24000L);
                wakeUpAllPlayers();
            }
        }
        Profiler.startSection("mobSpawner");
        SpawnerAnimals.performSpawning(this, false, spawnPeacefulMobs && worldInfo.getWorldTime() % 400L == 0L);
        Profiler.endStartSection("chunkSource");
        chunkProvider.unload100OldestChunks();
        int i = calculateSkylightSubtracted(1.0F);
        if(i != skylightSubtracted)
        {
            skylightSubtracted = i;
        }
        long l1 = worldInfo.getWorldTime() + 1L;
        if(l1 % (long)autosavePeriod == 0L)
        {
            Profiler.endStartSection("save");
            saveWorld(false, null);
        }
        worldInfo.setWorldTime(l1);
        Profiler.endStartSection("tickPending");
        tickUpdates(false);
        Profiler.endStartSection("tickTiles");
        updateBlocksAndPlayCaveSounds();
        Profiler.endSection();
    }
	
}